package top.hcode.hoj.controller.oj;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.annotation.AnonApi;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.entity.user.Dep;
import top.hcode.hoj.pojo.entity.user.UserInfo;
import top.hcode.hoj.service.oj.DepService;

import java.util.List;

@RestController
@RequestMapping("/api/oj/dep")
public class DepController {
    @Autowired
    private DepService depService;

//此方法是前端注册的时候，下拉框获取数据的方法
    @GetMapping("/list")
    @AnonApi
    public CommonResult<List<Dep>> getdeplist(@RequestParam(value = "oj", defaultValue = "ME") String oj) {
        return depService.getdeplists(oj);
    }

    //此方法是前端注册的时候，下拉框获取数据的方法
    @GetMapping("/list_list")
    public CommonResult<List<Dep>> list(@RequestParam(value = "oj", defaultValue = "ME") String oj) {
        return depService.getdeplists(oj);
    }

    //添加院系的方法
    @PostMapping("/adddep")
    public CommonResult<Void> adddep(@RequestBody Dep dep) {
        System.out.println(dep);
        boolean i = depService.adddep(dep);
        if (i ) {
            return  CommonResult.successResponse();
        }else {
            return CommonResult.errorResponse("新增失败");
        }

    }

    @PostMapping("/updatedep")
    public CommonResult<Void> updatedep(@RequestBody Dep dep) {
        return depService.updatedep(dep);
    }

    @DeleteMapping("/deletedep")
    public CommonResult<Void> deletedep(@RequestBody  Dep dep) {
        int i=  depService.deletedep(dep.getId());
        if (i ==1) {
            return  CommonResult.successResponse();
        }else {
            return CommonResult.errorResponse("删除失败");
        }
    }



}
